package com.jushu.storbox.actions;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

import com.jushu.storbox.constant.UiConstant;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.service.ServiceFactory;
import com.huawei.sharedrive.sdk.android.exception.ClientException;

public class SyncAction extends BaseAction {

	public void serverFolderChanged(Context context, Handler msgHandler,
			final FileFolderInfo node) {
		executeRunTask(new RealTaskRunnable(context, msgHandler) {
			@Override
			protected void doTask(Context context, Handler msgHandler) throws ClientException {
				boolean isUpdata = ServiceFactory.getRemoteFolderService().isUpdate(context, node);
			
				Message msg = msgHandler.obtainMessage();
				if(isUpdata) {
					msg.what = UiConstant.ITEM_SETITEM_HAVE_UPLOAD;
				} else {
					msg.what = UiConstant.ITEM_SETITEM_NOT_UPLOAD;
				}
				msg.sendToTarget();
			}
		});
	}
	
	public void serverFileChanged(Context context, Handler msgHandler,
			final FileFolderInfo node) {
		executeRunTask(new RealTaskRunnable(context, msgHandler) {
			@Override
			protected void doTask(Context context, Handler msgHandler) throws ClientException {
				boolean isUpdata = ServiceFactory.getRemoteFileService().isFileUpdate(context, node);
				
				Message msg = msgHandler.obtainMessage();
				if(isUpdata) {
					msg.what = UiConstant.ITEM_SETITEM_HAVE_UPLOAD;
				} else {
					msg.what = UiConstant.ITEM_SETITEM_NOT_UPLOAD;
				}
				msg.sendToTarget();
			}
		});
		
	}
}
